/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-05-25 20:48:21
 * @LastEditTime: 2024-05-25 20:49:39
 * @FilePath: /nest_study/src/common/utils/client-info.ts
 */
import Useragent from 'useragent';

//根据请求信息获取客户端信息
export const getClientInfo = (req: any) => {
    let userAgent: any;
    let agent: any;
    let os = '';
    let browser = '';
    try {
        userAgent = req.headers['user-agent']
        agent = Useragent.parse(userAgent);
        os = agent.os.toJSON().family
        browser = agent.toAgent()
    } catch { }

    const clientInfo = {
        userAgent,
        ip: req.ip,
        browser,
        os,
        location: ''
    }
    return clientInfo;
}